<?php

defined('BASEPATH') or die('forbidden');

/**
 * 记账模块
 * @author  Karson
 * @name   bill.php
 * @since   2013-2-27 23:22:55
 */
class Bill_Model extends Model {

    public $familyinfo = array();

    function _init() {
        
    }

    function get_family_combine() {
        $total = 0;
        $bill = array();
        $family_list = $this->family->get_family_list();
        $bill_list = array();
        if ($family_list) {
            $occurtime = get_unixtime('day', -2);
            $this->db->query("SELECT COUNT(*) AS bills, user_id FROM {pre}bill 
        WHERE user_id IN (" . (implode(",", array_keys($family_list))) . ") AND family='1' AND occurtime>={$occurtime} GROUP BY user_id");
            while ($row = $this->db->get_array()) {
                $bill[$row['user_id']] = $row['bills'];
                $total+=$row['bills'];
            }
            $bill_list = array();
            foreach ($family_list as $m => $n) {
                $n['bills'] = isset($bill[$n['id']]) ? $bill[$n['id']] : 0;
                $bill_list[$n['id']] = $n;
            }
        }
        $data = array('bills' => $total, 'bill_list' => $bill_list);
        return $data;
    }

}